package com.hrs.common.result;

import lombok.Data;

/**
 * @author 计算机系 ITAEM 摆渡人
 * @description
 * @date 2022/11/19 21:22
 */
@Data
public class Result<T> {
    private int code;
    private String msg;
    private T data;

    public static <T> Result<T> success(String msg,T data){
        return new Result<>(msg,data);
    }

    public static <T> Result<T> success(String msg){
        return new Result<>(CodeMsg.SUCCESS.getCode(),msg);
    }

    public static <T> Result<T> success(){
        return new Result<>(CodeMsg.SUCCESS.getCode(),CodeMsg.SUCCESS.getMsg());
    }

    public static <T> Result<T> success(T data){
        return new Result<>(data);
    }

    public static <T> Result<T> error(CodeMsg codeMsg){
        return new Result<T>(codeMsg);
    }

    public static <T> Result<T> error(String msg){
        return new Result<>(CodeMsg.ERROR.getCode(),msg);
    }

    public Result(CodeMsg codeMsg){
        this.code = codeMsg.getCode();
        this.msg = codeMsg.getMsg();
    }

    public Result(String msg,T date){
        this.code = CodeMsg.SUCCESS.getCode();
        this.msg = msg;
        this.data = date;
    }

    public Result(int code,String msg){
        this.code = code;
        this.msg = msg;
    }

    public Result(T data){
        this.msg = CodeMsg.SUCCESS.getMsg();
        this.code = CodeMsg.SUCCESS.getCode();
        this.data = data;
    }
}
